<?php
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller {

   public $defaultLang = 'cn';
   public $tplName = NULL;
   public $webConfig = array();
   public $htmlPower = NULL;
   public $member = NULL;
   
   public function _initialize(){
   
   
/*            $mobile="13900003333";
   		    $mwhere=array('sms_mobile'=>$mobile);
			$num=M_G('code')->where($mwhere)->getField("sms_mobile");
			
			
			var_dump($mwhere);exit;*/
   
   
        //$num=M('member_info')->where(array('mid'=>9))->setInc('user_money',100); 
		
		  // $mapx="123.437455";
		  
		  // $mapy="41.805034";
		  
		  //   echo "__UPLOAD__";
			// exit;
		  
		  
/*		  	 $data=M('member_info')->field('nickname,pic,comname,gpic')->where('mid=20')->find();
		     returnmemberSuccess("0","登录成功",0,21323,$data);
			 exit;
		   
		    $mapx=I('mapx');
		    $mapx=I('mapy');

		
			$num=$this->lbs((float)$mapx,(float)$mapx,9);
			
			var_dump($num); exit;*/

/*           
   			$data["sms_code"]= '1103';
			$data["sms_mobile"]= $mobile;
			$data["addtime"]= time();
			$data["type"]= 'reg';
		    $mwhere=array('type'=>'reg','sms_mobile'=>$mobile);
			$num=M_G('code')->where($mwhere)->getField("sms_mobile");*/
		/*	 $mobile="15840253396";
            $mwhere=array('sms_mobile'=>$mobile); */
	/*		if($num){
			M_G("code")->update($mwhere,$data);
			}else{
			M_G("code")->add($data);
			}*/
		/*	 $del['where']=array('sms_mobile'=>$mobile);
			 M_G("code")->delete($del);
			 echo $num;
			 exit;*/
			     
	/*			$mapx=1;
			    $mapy=2;
				$result=11;
			    if($mapx){
                $num=$this->lbs($mapx,$mapy,$result);
				}*/
				//echo $num;exit;
   

   }
   
   
	
   	 public function lbs($mapx=null,$mapy=null,$uid=null){    //通过传送定位的经度纬度
	

	   
		  //$map="123.437455,41.805034"; //匹配经度

		
		 //  $mapx=123.437455; //匹配经度
		  // $mapy=41.805034; //匹配经度
		
		    //$map=$mapx.",".$mapy;
	        if($mapx){
		
		    $city=6011; 
		    $city_name="沈阳";   //接口获取

			
			$newdata['city']=$city;
			$newdata['city_name']=$city_name;
			//$newdata['gps']=array(123.437455,41.805034);
			$newdata['gps']=array($mapx,$mapy);
			$newdata['addtime']=time();
			$newdata['uid']=$uid;
			$where['uid']=$uid;
			$num=M_G('users')->where($where)->count();
			 return  $newdata;
			//echo $num;
			//print_r($newdata);exit;
			if($num>0){
			M_G('users')->update($where,$newdata);
			}else{
			M_G('users')->add($newdata);
			}
			}else{
		
			$where['uid']=$uid;
			$newdata['city']=M_G('users')->where($where)->getField("city");
			$newdata['city_name']=M_G('users')->where($where)->getField("city_name");
			}
	        return  $newdata;
		
		
    }
   

   public function addPrPv(){
  		$mpr = M('guest_pr');
		$mpv = M('guest_pv');
		$guest['addtime'] = strtotime(date('Y-m-d'));
		$guest['ip']      = getIp();
		$mpv->add($guest);
		$isAdd = $mpr->where($guest)->getField('count(*)');
		if(!$isAdd)$mpr->add($guest);
   }


	public function up_down( $id , $arr , $flag){
			
			$arr_key_max = count($arr)-1;
			$id_key = array_search($id,$arr);
			
			if($flag=="up"){
			  $uid =  $id_key==0?false:$arr[$id_key-1];
			  
			  return $uid;
			}
			if($flag=="down"){
			  $did =  $id_key==$arr_key_max?false:$arr[$id_key+1];
			  return $did;
			}
		
	}
	
	
	public function baseValid(){
	    $config = require( __PHYSICS__."/Common/Conf/valid_index.php");
		//$config['codeSet']='0123456789';
		if(!$config['codeSet'])unset($config['codeSet']);
		if(!$config['zhSet'])unset($config['zhSet']);
	
		$Verify = new \Think\Verify($config);
		$Verify->entry();
	}
	
	public function bascCheckValid($valid){
		
		$config = require( __PHYSICS__."/Common/Conf/valid_admin.php");
		$verify = new \Think\Verify($config);
		return $verify->check($valid);
	}
	

	


	public function imgsave($pname,$picdata){   

		$imgDir = 'user/'.$pname.'/'.date("Y",time()).date("m",time()).'/';  //头像存储路径
		$path=__GUPLOAD__.'user/'.$pname.'/'.date("Y",time()).date("m",time());
		
		$filename=Data16to2name();     //图片重新命名 

		if(!file_exists($path)){
         mkdir($path,0777);
        }
	                            
        file_put_contents(__GUPLOAD__.$imgDir.$filename.'.jpg',$picdata);//写入文件中
		$data= $imgDir.$filename.'.jpg';
		return  $data; 

}
		
	 
      	
	
	

	
	

}